package com.chen.nio.zerocopy;

import java.io.DataOutputStream;
import java.io.FileInputStream;
import java.io.InputStream;
import java.net.InetSocketAddress;
import java.net.Socket;

public class OldIOClient {
    public static void main(String[] args) throws Exception {
        System.out.println("client start......");
        Socket client = new Socket();
        client.connect(new InetSocketAddress("127.0.0.1", 8989));
        DataOutputStream dataOutputStream = new DataOutputStream(client.getOutputStream());
        InputStream inputStream = new FileInputStream("D:\\baidu\\a.rar");

        byte[] buffer = new byte[1024 * 4];
        int len = 0;
        int size = 0;
        long startTime = System.currentTimeMillis();
        while ((len = inputStream.read(buffer)) >=0) {
            size += len;
            dataOutputStream.write(buffer);
        }
        long endTime = System.currentTimeMillis();
        System.out.println("发生的字节数:" + size + ",请求耗时:" + (endTime - startTime));
        inputStream.close();
        dataOutputStream.close();
        client.close();
    }
}
